<?php

class Emos_Views_View implements Emos_Views_Interface{
    
    protected $_views = 'views';
    
    protected $_autoView;
    
    protected $_action;
    
    protected $_extenstion = '.phtml';
    
    private static $_instance;
    /**
     *  private _layout for set default layout
     *  $_layout is true|| false
     *  true set layout
     *  false set layout default
     */
    private $_layout;
    public $baseUrl;

    public function __construct($options = array()) {
        ob_start(); 
        $this->setOption($options);
        self::$_instance = $this;
    }
    
    public function baseUrl(){
        return $this->baseUrl = Emos_Layout_Layout::getInstance()->baseUrl();
    }
    
    /**
     * statistic getinstance 
     */
    static function getIntance(){
        if (!self::$_instance) {
            self::$_instance = new Emos_Views_View($options);
        } 
        return self::$_instance;
    }
    
    /**
     * @desc Action controller 
     */
    public function render($fileName = null){
        $this->_autoView = true;
        
        $dirViews = PATH_MODULE.DS.$this->_views;
        
        if(!$fileName || !file_exists($file = $dirViews.DS.$fileName))
            return false;
//        return $this->content = file_get_contents($file);
        include $file;
        
    }
    
    protected function setOption($options){
        
        if(!$options || !$options['action'])
            return;
        
        $this->_action = $options['action'];
    }
    
    public function renderAuto(){
        if($this->_autoView){
            return;
        }
        
        $dirViews = PATH_MODULE.DS.$this->_views;
        
        if(!$this->_action || !file_exists($file = $dirViews.DS.$this->_action.$this->_extenstion))
            return false;
//        return $this->content = file_get_contents($file);
        include $file;
    }
    
    public function disableLayout(){
        
    }
    /**
     * @desc setNoRender file
     * @param type $render false is render | true is no render
     */
    public function setNoRender($render = false){
        
        $this->_autoView = $render;
        $this->renderAuto();
    }
    
    protected function _setHeader(){
        
    }
    
    protected function _setFooter(){
        
    }
    
    public function layoutDefault(){
        if($this->_layout)
            return false;
        Emos_Layout_Layout::getInstance()->layout();
    }
    
    public function setLayout(){
        $this->_layout = true;
    }
}